package com.atguigui.leetcode1;

import java.util.HashSet;
import java.util.Set;

/**
 * 771. 宝石与石头
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/7/24 8:41
 */
public class P771JewelsAndStones {
    public static void main(String[] args) {

    }

    public int numJewelsInStones(String jewels, String stones) {


        int ans = 0;

        Set<String> set = new HashSet<>();
        for (int i = 0; i < jewels.length(); i++) {
            set.add(jewels.substring(i, i + 1));
        }

        for (int i = 0; i < stones.length(); i++) {
            String c = stones.substring(i, i + 1);
            if (jewels.contains(c)) {
                ans++;
            }
        }

        return ans;
    }
}
